﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace easteradventure.World
{
  class ScreenManager : DrawableGameComponent
  {
    Game1 game;
      Screen currentScreen;
      SpriteBatch worldSpriteBatch;

      public ScreenManager(Game1 game, Screen startingScreen) : base(game)
      {
        this.game = game;
          currentScreen = startingScreen;
          worldSpriteBatch = new SpriteBatch(game.GraphicsDevice);
      }
public override void Update(GameTime gameTime){
  if (Keyboard.GetState().IsKeyDown(Keys.Back))
  {
    game.switchScreen();
  }
}
      public override void Draw(GameTime gameTime)
      {
          /* loop through the current screen's tiles and draw them */
          Game1 game = (Game1)this.Game;

          worldSpriteBatch.Begin();
          for (int x = 0; x < currentScreen.getWidth(); x++)
          {
              for (int y = 0; y < currentScreen.getHeight(); y++)
              {
                  worldSpriteBatch.Draw(currentScreen.getTile(x, y).Image, new Rectangle(x * Screen.TILE_WIDTH, y * Screen.TILE_HEIGHT, Screen.TILE_WIDTH, Screen.TILE_HEIGHT), Color.White);
              }
          }
          worldSpriteBatch.End();

      }
  }
}
